//
//  WeatherViewController.m
//  DayDayRun
//
//  Created by 卫建 on 16/1/7.
//  Copyright © 2016年 卫建. All rights reserved.
//

#import "WeatherViewController.h"
#import "WeatherTableViewCell.h"
#import "WeatherModel.h"
#import "WeatherDataManager.h"
@interface WeatherViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) IBOutlet UITableView *weatherTableView;

@end

@implementation WeatherViewController



- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.title = @"北京";
    
    //设置一个左侧返回Item
    [self addLeftItem];
    
    //设置代理
    self.weatherTableView.delegate = self;
    self.weatherTableView.dataSource = self;
    
    [self.weatherTableView registerNib:[UINib nibWithNibName:@"WeatherTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"WeatherTableViewCell"];
    
    [[WeatherDataManager sharedWeatherDataManager]getWeatherDataManager:^(BOOL isFinished) {
        
        [self.weatherTableView reloadData];
        
    }];
    
}

#pragma mark-------添加左侧返回按钮的方法
-(void)addLeftItem
{
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(leftItemAction:)];
    self.navigationItem.leftBarButtonItem = leftItem;
}

#pragma mark-------leftItem的点击响应事件
-(void)leftItemAction:(UIBarButtonItem *)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

#pragma mark-------实现dataScource默认必须实现的两个方法

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [WeatherDataManager sharedWeatherDataManager].weatherArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WeatherTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WeatherTableViewCell"];
    
    WeatherModel *weatherModel = [WeatherDataManager sharedWeatherDataManager].weatherArray[indexPath.row];
    
    [cell setCellDataWithWeatherModel:weatherModel];
    
    return cell;
}

#pragma mark------设置tableView cell的section
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

#pragma mark------设置cell的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}

//#warning 添加城市的名字

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}



@end
